﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Web.Http.Controllers;
using System.Web.Http.Filters;

namespace ldhWebApiWF
{
    public class AuthUkeyAttribute : ActionFilterAttribute
    {
        public override Task OnActionExecutingAsync(HttpActionContext actionContext, CancellationToken cancellationToken)
        {
            IEnumerable<string> ukey = null;
            if (actionContext.Request.Headers.TryGetValues("u-apikey", out ukey))
            {
                if (ukey.FirstOrDefault() == "111")
                {
                    return base.OnActionExecutingAsync(actionContext, cancellationToken);
                }
            }
            actionContext.Response = new HttpResponseMessage(System.Net.HttpStatusCode.Forbidden);
            return Task.FromResult<Object>(null);
        }
    }
}
